package org.lzy.shop.adapter

import android.content.Context
import android.view.ViewGroup
import androidx.appcompat.widget.AppCompatRatingBar
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.QuickViewHolder
import org.lzy.shop.R
import org.lzy.shop.response.Comment
import org.lzy.shop.util.setUrlRound

class CommentAdapter : BaseQuickAdapter<Comment, QuickViewHolder>() {


    override fun onCreateViewHolder(
        context: Context,
        parent: ViewGroup,
        viewType: Int
    ): QuickViewHolder {
        return QuickViewHolder(R.layout.item_comment, parent)
    }

    override fun onBindViewHolder(holder: QuickViewHolder, position: Int, item: Comment?) {
        item?.let {
            setUrlRound(item.avatarUrl, 60f, holder.getView(R.id.comment_iv_icon))
            holder.setText(R.id.comment_nickname, item.nickName)
            holder.setText(R.id.comment_content, item.content)
            val ratingBar = holder.getView<AppCompatRatingBar>(R.id.comment_ratingbarnum)
            ratingBar.numStars = item.starCount
            if (item.pics != null && item.pics.isNotEmpty()) {
                setUrlRound(item.pics[0], 20f, holder.getView(R.id.comment_pic))
            }
        }


    }


}